package com.ht.guice.fx.fxml;

import com.google.inject.AbstractModule;

/**
 * {@link com.google.inject.Module} enabling interaction between multiple controllers loaded in
 * one control.
 * 
 * @author Andy Till
 * @author Benjamin P. Jung
 */
public final class FXMLLoadingModule extends AbstractModule {

    public FXMLLoadingModule() {
        super();
    }

    @Override
    protected void configure() {

        // FXMLLoadingScope
//        final FXMLLoadingScope fxmlLoadingScope = new FXMLLoadingScope();
//        bind(FXMLLoadingScope.class).toInstance(fxmlLoadingScope);
//        bindScope(FXMLController.class, fxmlLoadingScope);
//        bindScope(FXMLComponent.class, fxmlLoadingScope);

        // GuiceFXMLLoader
        bind(GuiceFXMLLoader.class);

        // FXMLControllerTypeListener
/*        final FXMLControllerTypeListener fxmlControllerTypeListener = new FXMLControllerTypeListener();
        requestInjection(fxmlControllerTypeListener);
        bind(FXMLControllerTypeListener.class).toInstance(fxmlControllerTypeListener);
        bindListener(Matchers.any(), fxmlControllerTypeListener);

        // FXMLComponentTypeListener
        final FXMLComponentTypeListener fxmlComponentTypeListener = new FXMLComponentTypeListener();
        requestInjection(fxmlComponentTypeListener);
        bind(FXMLComponentTypeListener.class).toInstance(fxmlComponentTypeListener);
        bindListener(Matchers.any(), fxmlComponentTypeListener);

        // ControllerLookup
        bind(ControllerLookup.class).toProvider(new ControllerLookupProvider(fxmlLoadingScope));*/

    }


/*    private final class ControllerLookupProvider implements Provider<ControllerLookup> {
        private final FXMLLoadingScope fxmlLoadingScope;
        private ControllerLookupProvider(final FXMLLoadingScope fxmlLoadingScope) {
            super();
            this.fxmlLoadingScope = fxmlLoadingScope;
        }
        @Override
        public ControllerLookup get() {
            if (!fxmlLoadingScope.isActive()) {
                throw new IllegalStateException("A ControllerLookup instance cannot be injected while outside of the FXML Loading scope.");
            }
            return new ControllerLookup(fxmlLoadingScope.getIdentifiables());
        }
    }*/

}